package nl.boelen.game.screen.menubutton;

import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import nl.boelen.game.enums.GameState;

public abstract class MenuButton extends JButton {
    private Color pressedColor = Color.GRAY;
    private Color rolloverColor = Color.BLACK;
    private Color normalColor = Color.BLACK;
    private Color textColor = Color.WHITE;
    private Color borderColor = Color.WHITE;

    private int buttonWidth = 120;
    private int buttonHeigth = 30;

    public MenuButton(String text) {
        super(text);

        setBorderPainted(false);
        setBorder(BorderFactory.createLineBorder(borderColor, 1));
        setFocusPainted(false);
        setContentAreaFilled(false);
        setOpaque(true);

        setSize(buttonWidth, buttonHeigth);

        setBackground(normalColor);
        setForeground(textColor);
        setFont(new Font("Tahoma", Font.BOLD, 12));
        setText(text);

        addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent evt) {
                ButtonModel model = getModel();

                if (model.isPressed()) {
                    setBackground(pressedColor);
                    pressedButton();
                } else if (model.isRollover()) {
                    setBackground(rolloverColor);
                    setBorderPainted(true);
                } else {
                    setBackground(normalColor);
                    setBorderPainted(false);
                }
            }
        });
    }

    public void setButtonLocation(int x, int y) {
        setLocation(x - buttonWidth / 2, y);
    }

    public abstract void setVisibility(GameState gameState);

    public abstract void pressedButton();
}
